package faceoff.sample;

import me.prettyprint.cassandra.dao.SimpleCassandraDao;

import org.springframework.beans.factory.annotation.Autowired;

public class FaceService {
	@Autowired
	private SimpleCassandraDao simpleCassandraDao;

	public void setSimpleCassandraDao(SimpleCassandraDao simpleCassandraDao) {
		this.simpleCassandraDao = simpleCassandraDao;
	}

	public void insertBoard(String key, SampleBoard sampleBoard) {
		simpleCassandraDao.insert(key, SampleBoardColumn.TITLE.getName(), sampleBoard.getTitle());
		simpleCassandraDao.insert(key, SampleBoardColumn.CONTENT.getName(), sampleBoard.getContent());
		simpleCassandraDao.insert(key, SampleBoardColumn.USERID.getName(), sampleBoard.getUserId());
		simpleCassandraDao.insert(key, SampleBoardColumn.CREATE_DATE.getName(), sampleBoard.getCreateDate());
		simpleCassandraDao.insert(key, SampleBoardColumn.UPDATE_DATE.getName(), sampleBoard.getUpdateDate());
	}

	public SampleBoard selectBoard(String key) {
		String title = simpleCassandraDao.get(key, SampleBoardColumn.TITLE.getName());
		String content = simpleCassandraDao.get(key, SampleBoardColumn.CONTENT.getName());
		String userId = simpleCassandraDao.get(key, SampleBoardColumn.USERID.getName());
		String createDate = simpleCassandraDao.get(key, SampleBoardColumn.CREATE_DATE.getName());
		String updateDate = simpleCassandraDao.get(key, SampleBoardColumn.UPDATE_DATE.getName());

		return new SampleBoard(title, content, userId, createDate, updateDate);
	}

	public void deleteBoard(String key) {
		simpleCassandraDao.delete(SampleBoardColumn.TITLE.getName(), key);
		simpleCassandraDao.delete(SampleBoardColumn.CONTENT.getName(), key);
		simpleCassandraDao.delete(SampleBoardColumn.USERID.getName(), key);
		simpleCassandraDao.delete(SampleBoardColumn.CREATE_DATE.getName(), key);
		simpleCassandraDao.delete(SampleBoardColumn.UPDATE_DATE.getName(), key);
	}
}
